<?php


namespace app\api\console;


use app\api\service\PharmacyService;
use think\console\Command;
use think\console\Input;
use think\console\Output;
use think\Log;

class SyncLocationToRedis extends Command
{
    protected function configure()
    {
        $this
            // 命令的名字（"think" 后面的部分）
            ->setName('app:sync:location:to:redis')

            // 运行 "php think list" 时的简短描述
            ->setDescription('同步药店的经纬度数据到redis geo.')

            // 运行命令时使用 "--help" 选项时的完整命令描述
            ->setHelp("同步药店的经纬度数据到redis geo...")
        ;
    }

    protected function execute(Input $input, Output $output)
    {

        $pharmacyService = new PharmacyService();

        $data = $pharmacyService->getPharmacyInfoList();

        if(count($data) > 0){

            foreach ($data as $datum){

                try{

                    $datumObject = new \stdClass();

                    $datumObject->longitude = $datum['longitude'];

                    $datumObject->latitude = $datum['longitude'];

                    $datumObject->id = $datum['id'];

                    $pharmacyService->syncToRedis($datumObject);

                }catch (\Exception $e){
                    Log::error("同步到redis数据异常");
                    Log::error($e->getMessage());
                }


            }

        }


    }
}